﻿/*
// CHANGE LOG
mod 16 jun 07 - ddb
	ver 2.02
	changed:
		
	added:
		toString() method
		className_str:String
		version_str:String

*/
/*
// METHOD TABLE:
//
function enableTargetClips(p_tipData_array:Array):Void {
function showScaleNineClip(p_target_mc:MovieClip):Void {
function hideScaleNineClip(p_scaleNineClip_mc:MovieClip):Void {
function disableTargetClips(p_tipData_array:Array):Void {
private function toString():Void{
*/
class com.utils.ScaleNineManager {
	private var className_str:String;
	private var version_str:String;
	//
	// shell properties
	//
	static var SCOPE_obj:Object;
	//
	//
	// constructor
	function ScaleNineManager(p_scope_obj:Object) {
		className_str = "  ScaleNineManager";
		version_str = "v2.02";
		trace(this);
		// set scope
		if (p_scope_obj != undefined) SCOPE_obj = p_scope_obj;
	}
	// methods

	public function enableTargetClips(p_tipData_array:Array):Void {
		//trace("enableTargetClips()");
		// 
		//	OBJECT PROPERTIES
		//	tip_obj.scaleNineClip_mc:String - instanceName of clip to use as tooTip 
		//	tip_obj.targetClip_mc:String - instanceName of clip to add rollOver behavior to
		//	tip_obj.text_str:String - text to display
		//	tip_obj.width_num:Number - width of tooltip (height dynamically resizes)
		//	tip_obj.event_str:String - "onRelease","onRollOver" what event triggers appearance of scaleNine clip
		//	tip_obj.followMouse_bool:Boolean - true/false whether is static postion or follows mouse
		//	tip_obj.offsets_array:Array - [20,40] [xOffset_num:Number, yOffset_num:Number]
		//	tip_obj.margins_array:Array - [10,10,10] [leftMargin_num:Number, rightMargin_num:Number, topMargin_num:Number]
		//
		// loop through array
		for (var i:Number = 0; i < p_tipData_array.length; i++) {
			//trace("i:"+i);
			// next item in array
			var tip_obj:Object = p_tipData_array[i];
			// reference to target clip
			var targetClip_mc:MovieClip = tip_obj.targetClip_mc;
			//trace("targetClip_mc:"+targetClip_mc);
			// reference to scaleNine clip
			targetClip_mc.scaleNineClip_mc = tip_obj.scaleNineClip_mc;
			// pass tip_obj to target clip
			targetClip_mc.tip_obj = tip_obj;
			// type of event to respond to
			var event_str:String = tip_obj.event_str;
			// attach event handlers to target clip
			if (event_str == "onRollOver") {
				// add showScaleNineClip() to rollOver event handler
				targetClip_mc.onRollOver = function() {
					//trace("rollOver");
					this.tip_obj.scaleNineMgr.showScaleNineClip(this);
				};
				// add hideScaleNineClip() to rollOut event handler
				targetClip_mc.onRollOut = function() {
					//trace("rollOut");
					this.tip_obj.scaleNineMgr.hideScaleNineClip(this.scaleNineClip_mc);
				};
			} else if (event_str == "onRelease"){
				// add showScaleNineClip() to release event handler
				targetClip_mc.onRelease = function() {
					//trace("onRelease");
					this.tip_obj.scaleNineMgr.showScaleNineClip(this);
				};
				// add hideScaleNineClip() to release event handler
				targetClip_mc.scaleNineClip_mc.upperRow_mc.rightColumn_mc.closeBtn_mc.onRelease = function() {
					//trace("closeBtn_mc.onRelease()");
					tip_obj.scaleNineMgr.hideScaleNineClip(this._parent._parent._parent);
				};
			}
		}
	}
	public function showScaleNineClip(p_target_mc:MovieClip):Void {
		//trace("showScaleNineClip()");
		//trace("  p_target_mc:"+p_target_mc);
		// 
		//	OBJECT PROPERTIES
		//	tip_obj.scaleNineClip_mc:String - instanceName of clip to use as tooTip 
		//	tip_obj.targetClip_mc:String - instanceName of clip to add rollOver behavior to
		//	tip_obj.text_str:String - text to display
		//	tip_obj.width_num:Number - width of tooltip (height dynamically resizes)
		//	tip_obj.event_str:String - "onRelease","onRollOver" what event triggers appearance of scaleNine clip
		//	tip_obj.followMouse_bool:Boolean - true/false whether is static postion or follows mouse
		//	tip_obj.offsets_array:Array - [20,40] [xOffset_num:Number, yOffset_num:Number]
		//	tip_obj.margins_array:Array - [10,10,10] [leftMargin_num:Number, rightMargin_num:Number, topMargin_num:Number]
		//
		var tip_obj:Object = p_target_mc.tip_obj;
		var scaleNineClip_mc:MovieClip = tip_obj.scaleNineClip_mc;
		var text_str:String = tip_obj.text_str;
		var width_num:Number = tip_obj.width_num;
		var event_str:String = tip_obj.event_str;
		var followMouse_bool:Boolean = tip_obj.followMouse_bool;
		var xOffset_num:Number = tip_obj.offsets_array[0];
		var yOffset_num:Number = tip_obj.offsets_array[1];
		var leftMargin_num:Number = tip_obj.margins_array[0];
		var rightMargin_num:Number = tip_obj.margins_array[1];
		var topMargin_num:Number = tip_obj.margins_array[2];
		// set text
		// function setText(p_sText:String, p_maxWidth_num:Number, p_leftMargin_num:Number, p_topMargin_num:Number, p_rightMargin_num:Number):Void 
		scaleNineClip_mc.setText(text_str, width_num, leftMargin_num, topMargin_num, rightMargin_num);//,14, 22, 8);
		// position tooltip
		// by using _xmouse/_ymouse, can use on nested targetClip_mc's without worrying about _parent._x issues 
		var nextX_num:Number = _xmouse + xOffset_num;
		var nextY_num:Number = _ymouse + yOffset_num;
		if (followMouse_bool) {
			scaleNineClip_mc.onEnterFrame = function() {
				//trace("onEnterFrame()");
				var nextX_num:Number = _xmouse + xOffset_num;
				var nextY_num:Number = _ymouse + yOffset_num;
/*				
				// code to adjust scaleNineClip_mc position if off-screen
				var currX_num:Number = this._x;
				var currY_num:Number = this._y;
				var clearance_num:Number = this._width;
				if ((nextX_num - clearance_num) < 0) {
					//trace("too far left");
					//nextX_num = (clearance_num - 4);
				}
				if ((nextX_num + clearance_num) > Stage.width) {
					//trace("too far right");
					//nextX_num = (Stage.width - clearance_num - 12);
				}
*/
				this._x = nextX_num;
				this._y = nextY_num;
			};
		} else {
			scaleNineClip_mc._x = nextX_num;
			scaleNineClip_mc._y = nextY_num;
		}
		// show tooltip
		// if targetClip's are too close together,
		// can't see any alphaTo transition,
		// don't notice the text changed 
		// 
		//
		//if (event == "rollOver") {
			//if (followMouse){
				//if (scaleNineClip_mc._visible == true && scaleNineClip_mc._alpha > 50){
				//} else{
				//}
			//} else {
			//}
		//} else {
		//}
		// show tooltip
		scaleNineClip_mc._visible = true;
		//scaleNineClip_mc.stopTween();
		scaleNineClip_mc.alphaTo(100, .5, "easeInQuad");
	}
	public function hideScaleNineClip(p_scaleNineClip_mc:MovieClip):Void {
		//trace("hideScaleNineClip()");
		//trace(" p_scaleNineClip_mc:"+p_scaleNineClip_mc._name);
		// hide toolTip
		p_scaleNineClip_mc.stopTween();
		p_scaleNineClip_mc.alphaTo(0, .5, "easeOutQuad", 0, function () {
			// clear text
			this.clearText();
		});
		// position tooltip
		p_scaleNineClip_mc.onEnterFrame = null;
	}
	public function disableTargetClips(p_tipData_array:Array):Void {
		//trace("disableTargetClips()");
		// tip_obj = p_tipData_array[i];
		// tip_obj.targetClip_mc:String - instanceName of clip to add rollOver behavior to
		// loop through array
		for (var i:Number = 0; i < p_tipData_array.length; i++) {
			var tip_obj:Object = p_tipData_array[i];
			var targetClip_mc:MovieClip = tip_obj.targetClip_mc;
			var event_str:String = tip_obj.event_str;
			if (event_str == "onRelease") {
				//delete targetClip_mc["onRelease"];
				delete targetClip_mc.onRelease;
			} else if (event_str == "onRollOver") {
				//delete targetClip_mc["onRollOver"];
				//delete targetClip_mc["onRollOut"];
				delete targetClip_mc.onRollOver;
				delete targetClip_mc.onRollOut;
			} else {
				//trace("error");
			}
		}
	}
	private function toString():String {
		return className_str + " ("+version_str+")";
	}
}